package javamusic.Servlet.Producto;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javamusic.DAO.*;
import javamusic.negocio.GestionProducto;
import javamusic.excepcion.DAOExcepcion;

/**
 * Servlet implementation class ServletProductoModificar
 */
@WebServlet("/ServletProductoModificar")
public class ServletProductoModificar extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public ServletProductoModificar() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		int  idproducto = Integer.parseInt(request.getParameter("idproducto"));	
		String  nombre = request.getParameter("nombre");
		Double  precio = Double.parseDouble(request.getParameter("precio"));	
		int  elog = Integer.parseInt(request.getParameter("elog"));	
		int  disponible = Integer.parseInt(request.getParameter("disponible"));	
		int  idtipoproducto = Integer.parseInt(request.getParameter("idtipoproducto"));	
  	
		try {
			GestionProducto negocio = new GestionProducto();
			System.out.println(negocio);
			negocio.ProductoActulizar(idproducto, nombre, precio, elog, disponible, idtipoproducto);
			response.sendRedirect(request.getContextPath()	+ "/ServletProductoBuscar");
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}
		}

	
}
